package com.ibl.rover.lite.common.bean;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

public class ProductBean extends BaseBean {

	@ColumnOrder(Order = 1)
	private String brandCode;
	@ColumnOrder(Order = 2)
	private String productCategoryId;
	@ColumnOrder(Order = 3)
	private String description;
	@ColumnOrder(Order = 4)
	private String productCode;
	@ColumnOrder(Order = 5)
	private String unitPrice;
	@ColumnOrder(Order = 6)
	private long displaySequence;

	private static AutomatedQueryStatement AUTO_GEN_QUERY;

	public static final String COL_BRAND_CODE = "BRAND_CODE";
	public static final String COL_PRODUCT_CATEGORY_ID = "PRODUCT_CATEGORY_ID";
	public static final String COL_DESCRIPTION = "DESCRIPTION";
	public static final String COL_PRODUCT_CODE = "PRODUCT_CODE";
	public static final String COL_UNIT_PRICE = "UNIT_PRICE";
	public static final String COL_DISPLAY_SEQUENCE = "DISPLAY_SEQUENCE";

	public static final int IDX_COL_BRAND_CODE = 1;
	public static final int IDX_COL_PRODUCT_CATEGORY_ID = 2;
	public static final int IDX_COL_DESCRIPTION = 3;
	public static final int IDX_COL_PRODUCT_CODE = 4;
	public static final int IDX_COL_UNIT_PRICE = 5;
	public static final int IDX_COL_DISPLAY_SEQUENCE = 6;

	static {
		AUTO_GEN_QUERY = SQLiteDatabaseHelper
				.getAutoGeneratedStmts(ProductBean.class);
	}

	@Override
	public void bind(SQLiteStatement sqlLiteStatement) {
		sqlLiteStatement.bindString(IDX_COL_BRAND_CODE, getBrandCode());
		sqlLiteStatement.bindString(IDX_COL_DESCRIPTION, getDescription());
		sqlLiteStatement.bindLong(IDX_COL_DISPLAY_SEQUENCE,
				getDisplaySequence());
		sqlLiteStatement.bindString(IDX_COL_PRODUCT_CATEGORY_ID,
				getProductCategoryId());
		sqlLiteStatement.bindString(IDX_COL_PRODUCT_CODE, getProductCode());
		sqlLiteStatement.bindString(IDX_COL_UNIT_PRICE, getUnitPrice());

	}

	@Override
	public <T extends BaseBean> T cursorBind(Cursor cursor) {
		ProductBean productBean = new ProductBean();
		productBean.set_id(cursor.getInt(IDX_COL_ID));
		productBean.setBrandCode(cursor.getString(IDX_COL_BRAND_CODE));
		productBean.setDescription(cursor.getString(IDX_COL_DESCRIPTION));
		productBean
				.setDisplaySequence(cursor.getLong(IDX_COL_DISPLAY_SEQUENCE));
		productBean.setProductCategoryId(cursor
				.getString(IDX_COL_PRODUCT_CATEGORY_ID));
		productBean.setProductCode(cursor.getString(IDX_COL_PRODUCT_CODE));
		productBean.setUnitPrice(cursor.getString(IDX_COL_UNIT_PRICE));

		return (T) productBean;
	}

	@Override
	public <T extends BaseBean> T cursorInit(Cursor cursor) {
		this.setBrandCode(cursor.getString(IDX_COL_BRAND_CODE));
		this.setDescription(cursor.getString(IDX_COL_DESCRIPTION));
		this.setDisplaySequence(cursor.getLong(IDX_COL_DISPLAY_SEQUENCE));
		this.setProductCategoryId(cursor.getString(IDX_COL_PRODUCT_CATEGORY_ID));
		this.setProductCode(cursor.getString(IDX_COL_PRODUCT_CODE));
		this.setUnitPrice(cursor.getString(IDX_COL_UNIT_PRICE));
		return (T) this;
	}

	@Override
	public String getCreateTableQuery() {

		return AUTO_GEN_QUERY.getCreateTableQuery();
	}

	@Override
	public String getInsertQuery() {

		return AUTO_GEN_QUERY.getPreparedInsertQuery();
	}

	@Override
	public String getDeleteQuery() {

		return AUTO_GEN_QUERY.getPreparedDeleteQuery();
	}

	@Override
	public String getUpdateQuery() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getTableName() {

		return AUTO_GEN_QUERY.getTableName();
	}

	public String getBrandCode() {
		return brandCode;
	}

	public void setBrandCode(String brandCode) {
		this.brandCode = brandCode;
	}

	public String getProductCategoryId() {
		return productCategoryId;
	}

	public void setProductCategoryId(String productCategoryId) {
		this.productCategoryId = productCategoryId;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getProductCode() {
		return productCode;
	}

	public void setProductCode(String productCode) {
		this.productCode = productCode;
	}

	public String getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(String unitPrice) {
		this.unitPrice = unitPrice;
	}

	public long getDisplaySequence() {
		return displaySequence;
	}

	public void setDisplaySequence(long displaySequence) {
		this.displaySequence = displaySequence;
	}

	@Override
	public boolean equals(Object o) {

		if (this == o) {
			return true;
		}
		ProductBean productBean = null;

		if (o instanceof ProductBean) {
			productBean = (ProductBean) o;
		} else {
			return false;
		}
		if (productBean.get_id() == this.get_id()
				&& this.getBrandCode().equals(productBean.getBrandCode())
				&& this.getDescription().equals(productBean.getDescription())
				&& this.getDisplaySequence() == productBean
						.getDisplaySequence()
				&& this.getProductCategoryId().equals(
						productBean.getProductCategoryId())
				&& this.getProductCode().equals(productBean.getProductCode())
				&& this.getUnitPrice().equals(productBean.getUnitPrice())) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public ContentValues bindContentValues() {
		// TODO Auto-generated method stub
		return null;
	}
}
